package org.alis.rpc.route.impl;

import org.alis.rpc.common.protocol.RpcProtocol;
import org.alis.rpc.route.AbstractRpcLoadBalance;

import java.util.List;
import java.util.Random;

/**
 * RpcLoadBalanceRandom desc: 随机算法
 *
 * @author luochuan
 * @date 2020/10/9 14:49
 */
public class RpcLoadBalanceRandom<V> extends AbstractRpcLoadBalance<V> {

    private Random random = new Random();

    @Override
    protected RpcProtocol doRoute(String serviceKey, List<RpcProtocol> addressList) {
        // Random
        return addressList.get(random.nextInt(addressList.size()));
    }
}
